package com.gewu.pm.ui.adapter.delivery;

import android.content.Context;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ImageView;
import android.widget.TextView;
import android.widget.Toast;

import androidx.annotation.NonNull;

import com.gewu.pm.R;
import com.gewu.pm.app.AppAdapter;
import com.gewu.pm.bean.DeliveryOrderBean;

/**
 * 配送订单列表适配器
 */
public class DeliveryOrderAdapter extends AppAdapter<DeliveryOrderBean> {
    Context context;

    public DeliveryOrderAdapter(Context context) {
        super(context);
        this.context = context;
    }

    @NonNull
    @Override
    public ViewHolder onCreateViewHolder(@NonNull ViewGroup parent, int viewType) {
        return new ItemViewHolder();
    }

    private final class ItemViewHolder extends AppAdapter<?>.ViewHolder {

        private final TextView mOrderIdView;
        private final TextView mStatusView;
        private final TextView mTerminalNameView;
        private final ImageView ivNavigation;

        private ItemViewHolder() {
            super(R.layout.delivery_order_item);
            mOrderIdView = findViewById(R.id.tv_order_id);
            mStatusView = findViewById(R.id.tv_status);
            mTerminalNameView = findViewById(R.id.tv_terminal_title);
            ivNavigation = findViewById(R.id.iv_navigation);
        }

        @Override
        public void onBindView(int position) {
            DeliveryOrderBean item = getItem(position);

            // 设置订单编号
            mOrderIdView.setText("订单编号:" + item.getOrderId());

            // 设置终端名称
            mTerminalNameView.setText(item.getTerminalName());

            // 设置状态文字和颜色
            mStatusView.setText(item.getStatusText());

            // 根据状态设置不同颜色
            switch (item.getType()) {
                case 1: // 待发货
                    mStatusView.setTextColor(getColor(R.color.orange_01));
                    break;
                case 2: // 待签收
                    mStatusView.setTextColor(getColor(R.color.orange_01));
                    break;
                case 3: // 已签收
                    mStatusView.setTextColor(getColor(R.color.green_label));
                    break;
                case 4: // 已取消
                    mStatusView.setTextColor(getColor(R.color.cb9));
                    break;
            }
            ivNavigation.setOnClickListener(new View.OnClickListener() {
                @Override
                public void onClick(View view) {
                    Toast.makeText(context, "导航", Toast.LENGTH_LONG).show();
                }
            });
        }
    }
}

